﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using DreamBuilder.Common;
using Common;
using Web.SystemConfig.Services;
using System.Data;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Configuration;

namespace Web.Views.SystemConfig
{
    public partial class OA_Sys_InitUserPwd : PageBase
    {
        #region 变量定义
        /// <summary>
        /// Business类
        /// </summary>
        [Dependency]
        public IChangePassword BUSChangePassword
        {
            get;
            set;
        }
        [Dependency]
        public IAuth_User SystemConfigComponent
        {
            get;
            set;
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            this.txtName.Attributes["contentEditable"] = "false";
            if (!IsPostBack)
            {
            }
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            this.txtName.Text = "";
            this.txtId.Value = string.Empty;
            this.txtNewPassword.Text = "";
            this.txtConfirm.Text = "";
        }

        

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            string userOALoginName = this.txtId.Value.Trim();
            string userInitPwd = EncryptDecrypt.EncryptPassword(this.txtNewPassword.Text.Trim(), "MD5");
            string loginpassword = this.txtNewPassword.Text.Trim();

            

            if (BUSChangePassword.UpdateUserPasswd(this.txtId.Value, userInitPwd) == 1)
            {
                this.ShowMsg("初始化密码成功！");
                WriteUserLog(this.CurrentUser.User_Name + "修改了  " + this.txtName.Text + "【" + this.txtId.Value + "】的密码成功!", OracleLogType.System);
            }
            else
            {
                this.ShowMsg("初始化密码失败！");
                WriteErrorLog(this.CurrentUser.User_Name + "修改 " + this.txtName.Text + "【" + this.txtId.Value + "】的密码失败!", OracleLogType.System);
            }

        }

        public string GetLoginNameFromUID(string userID)
        {
            var table=SystemConfigComponent.GetUserInfo(userID);
            if (table!=null && table.Rows.Count>0)
            {
                return table.Rows[0]["OALogin_ID"].ToString();
            }
            return "";
        }

    }
}
